$(function() {
	function init() {
		var details = JSON.parse(sessionStorage.getItem("orderItemDetails"));
		console.log(details);
		var userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
		if(userInfo) {
			$('#userName').html("你好，" + userInfo.name);
		} else {
			window.location.href = "../index.html";
		}
		//显示附件图片
		if(details.fileIds){
			for(var i = 0; i < details.fileIds.length; i++) {
				$.ajax({
					url: baseUrl + "/palmmall-server/rest/media/fileget/" + details.fileIds[i],
					cache: false,
					async: false,
					dataType: 'json', //服务器返回json格式数据
					type: 'get', //HTTP请求类型
					contentType: "application/json",
					timeout: 20000, //超时时间设置为10秒
					success: function(res) {
						if(res.success) {
							$('.fileImgs').append('<img src="' + res.data + '" class="img-thumbnail" />');
						} else {
							layer.msg(res.message)
						}
					},
					error: function(res) {
						console.log(res);
						layer.msg("网络出错……");
					}
				})
			}
		}

		if(details.bizState == "ineffect") {
			details.bizState = "未生效";
		} else if(details.bizState == "aborted"){
			details.bizState = "已作废";
			$('.editOrder').hide();
		} else if(details.bizState == "receipted"){
			details.bizState = "已收款";
			$('.editOrder').hide();
		} else if(details.bizState == "receipting"){
			details.bizState = "部分收款";
			$('.editOrder').hide();
		} else if(details.bizState == "declaration"){
			details.bizState = "已报单";
			$('.editOrder').hide();
		} else if(details.bizState == "passed"){
			details.bizState = "已通过";
			$('.editOrder').hide();
		} else if(details.bizState == "rejected"){
			details.bizState = "已驳回";
			$('.editOrder').hide();
		}
		if(details.deliveryMode == "delivery") {
			details.deliveryMode = "送货";
		} else if(details.deliveryMode == "selfExtract"){
			details.deliveryMode = "自提";
		}else{
			details.deliveryMode = "货运";
		}
		if(details.install == true){
			details.install = "是";
		}else{
			details.install = "否";
		}
		if(details.paymentCategory == "full") {
			$('#paymentMode').html("全款"); //全款
		} else {
			$('#paymentMode').html("定金&nbsp;" + details.preDeposit); //定金
		}
		
		var totalPrice = 0;//记录合计
		var totalCount = 0;//记录总件数
		//显示商品列表
		for(var i = 0; i < details.lines.length; i++) {
			if(details.lines[i].model == null){
				details.lines[i].model = '';
			}
			if(details.lines[i].specification == null){
				details.lines[i].specification = '';
			}
			if(details.lines[i].originalPrice == 0){
				$('.goodlist').prepend('<tr>' +
				'<td>' +
				'<dl>' +
				'<dt class="fl"><!--<img id="goodsImg" src="../img/goods3.png"/>--></dt>' +
				'<dd class="fl text-left">' +
				'<p class="f18" id="goodsCodeName">' + details.lines[i].code + '&nbsp;' + details.lines[i].name + '</p>' +
				'<p>型号：<span id="goodsModel">' + details.lines[i].model + '</span></p>' +
				'<p>规格：<span id="goodsGuige">' + details.lines[i].specification + '</span></p>' +
				'</dd>' +
				'</dl>' +
				'</td>' +
				'<td>￥<span id="orgPrice">' + details.lines[i].originalPrice + '</span></td>' +
				'<td id="countnum">' + details.lines[i].qty + '</td>' +
				'<td>￥<span id="zhekouPrice">' + details.lines[i].price + '</span></td>' +
				'<td>￥<span id="xiaojiPrice">' + details.lines[i].stdTotal + '</span></td>' +
				'<td><span id="mode">' + details.deliveryMode + '</span></td>' +
				'</tr>')
			}else{
				$('.goodlist').append('<tr>' +
					'<td>' +
					'<dl>' +
					'<dt class="fl"><!--<img id="goodsImg" src="../img/goods3.png"/>--></dt>' +
					'<dd class="fl text-left">' +
					'<p class="f18" id="goodsCodeName">' + details.lines[i].code + '&nbsp;' + details.lines[i].name + '</p>' +
					'<p>型号：<span id="goodsModel">' + details.lines[i].model + '</span></p>' +
					'<p>规格：<span id="goodsGuige">' + details.lines[i].specification + '</span></p>' +
					'</dd>' +
					'</dl>' +
					'</td>' +
					'<td>￥<span id="orgPrice">' + details.lines[i].originalPrice + '</span></td>' +
					'<td id="countnum">' + details.lines[i].qty + '</td>' +
					'<td>￥<span id="zhekouPrice">' + details.lines[i].price + '</span></td>' +
					'<td>￥<span id="xiaojiPrice">' + details.lines[i].stdTotal + '</span></td>' +
					'<td><span id="mode">' + details.deliveryMode + '</span></td>' +
					'</tr>')
			}
			totalPrice += details.lines[i].stdTotal;
			totalCount += details.lines[i].qty;
		}

		$('.myorder').html(details.billNumber); //填充订单编号
		$('#orderstate').html(details.bizState); //订单状态
		$('#receiver').html(details.customerName); //收件人
		$('#receiverPhone').html(details.customerTelephone); //收件人电话
		$('#receiverAddress').html(details.receiptAddress); //收件人地址
		$('#memberPhone').html(details.memberCardNo); //会员电话号？
		$('#designPhone').html(details.designerPhone); //设计师电话号
		$('#boothPhone').html(details.boothTelephone); //营业员电话号
		$('#orderDate').html(details.orderDate); //促销日期？订单日期？
		var str = '';
		if(details.preActivities){
			for(var i=0; i<details.preActivities.length; i++){
				str += details.preActivities[i].activityName + "; ";
			}
		}
		$('#activity').html(str); //活动
		$('#isInstall').html(details.install); //配送方式
		$('#deliveryDate').html(details.appointmentDeliveryDate.split(" ")[0]); //配送日期
		$('#gift').html(details.gift); //赠品
		$('#voucher').html(details.voucher); //礼券
		$('.remarksInfo').html(details.remark); //备注
		$('.totalCount').html(totalCount);//共多少商品
		$('.totalPrice').html(totalPrice);//合计多少钱
	}
	init();
	
	//修改订单事件
	$('.editOrder').click(function(){
		layer.confirm('你确定要修改该订单？', {
			btn: ['确定', '取消'] //按钮
		}, function() {
			window.location.href = "shopCart.html?editOrder=true";			
		});
	})
})